﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LoginAjax.ascx.cs" Inherits="MyTemplate.LoginAjax" %>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            $("#<%=btnLogin.ClientID %>").click(function (e) {
                e.preventDefault();

                if (($("#<%=txtUserID.ClientID %>").val() == "") | ($("#<%=txtPW.ClientID %>").val() == ""))
                    alert("Please enter your login details");
                else
                    CheckLogin();
            });

            function CheckLogin() {
                var LoginObj = new Object();
                LoginObj.UserName = $("#<%=txtUserID.ClientID %>").val();
                LoginObj.Password = $("#<%=txtPW.ClientID %>").val();

                //Define DTO i.e. Data Transfer Object as follows
                var DTO = { 'userLogin': LoginObj };

                $.ajax({
                    type: "POST",
                    url: "Login.asmx/CheckLogin",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: JSON.stringify(DTO),
                    success: function (msg) {
                        if (msg.d)
                            alert("Valid Login");
                        else
                            alert("Invalid Login");
                    },
                    error: function (xhr, status, error) {
                        alert("An error has occurred during processing: " + error);
                    }
                });
            }

        });
    </script>
    <style media="screen" type="text/css">
    .header
    {
    	background-color:Gray;
    	font-weight:bold;
    	color:White;
    	text-align:center;
    }
    .alertmsg
    {
    	color:#FF0000;
    }
    </style>
    <div>
        <asp:Panel ID="Panel1" runat="server">    
        <ul class="inline-list right">
        <li><asp:Label ID="Label1" runat="server" Text="id"></asp:Label></li>
        <li><asp:TextBox ID="txtUserID" runat="server" Width="95px"></asp:TextBox></li>
        <li><asp:Label ID="Label2" runat="server" Text="pw"></asp:Label></li>
        <li><asp:TextBox ID="txtPW" runat="server" Width="103px" TextMode="Password"></asp:TextBox></li>
        <li><asp:Button ID="btnLogin" runat="server" Text="Login" /></li>
        </ul>
        </asp:Panel>
        <ul class="inline-list right">
        <li><asp:Label ID="lblResult" runat="server"></asp:Label></li>
        <li><asp:Button ID="btnLogout" runat="server" onclick="btnLogout_Click" 
            Text="Logout" Visible="False" /></li>
            </ul>
    </div>

        <br />
    <div align="center" class="alertmsg">
    </div>


